package org.lyl.taobao.service;

import org.lyl.taobao.api.ICommodityService;
import org.lyl.taobao.api.entity.Commodity;
import org.lyl.taobao.api.utils.DruidConnectionUtils;
import org.lyl.taobao.dao.ICommodityDao;
import org.lyl.taobao.dao.impl.CommodityDaoImpl;

import java.util.List;

/**
 * @Author: Re
 * @Date: 2021/4/2 17:26
 */
public class CommodityServiceImpl implements ICommodityService {
    DruidConnectionUtils druidConnectionUtils=new DruidConnectionUtils();
    ICommodityDao iCommodityDao = new CommodityDaoImpl();
    public boolean addCommodity(Commodity commodity) {
        return iCommodityDao.insertCommodity(druidConnectionUtils.getConnection(),commodity);
    }

    public List<Commodity> checkAllCommodity() {
        return iCommodityDao.checkAllCommodity(druidConnectionUtils.getConnection());
    }

    public Commodity checkCommodityByC_Id(Integer c_Id) {
        return iCommodityDao.checkCommodityByC_Id(druidConnectionUtils.getConnection(), c_Id);
    }

    public List<Commodity> checkCommodityById(Integer UserId) {
        return iCommodityDao.checkCommodityById(druidConnectionUtils.getConnection(),UserId);
    }

    public boolean deleteCommodity(int c_Id) {
        return iCommodityDao.deleteCommodity(druidConnectionUtils.getConnection(),c_Id);
    }

    public boolean updateCommodity(int c_Id, String c_Name, float c_Price) {
        return iCommodityDao.updateCommodity(druidConnectionUtils.getConnection(),c_Id,c_Name,c_Price);
    }

    public float getCommodityPriceByC_Id(Integer c_Id) {
        return iCommodityDao.getCommodityPriceByC_Id(druidConnectionUtils.getConnection(),c_Id);
    }
}
